package cn.z2huo.demo.jakarta.validation.controller;

import cn.z2huo.demo.jakarta.validation.model.dto.TestInListReqDTO;
import cn.z2huo.demo.jakarta.validation.model.dto.TestReqDTO;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *
 * @author z2huo
 */
@Slf4j
@RestController
public class TestController {

    @PostMapping("/parameterValid")
    public void parameterValid(@RequestParam @Length(max = 11) String phoneNumber) {
        log.info("TestController#parameterValid, phoneNumber: {}", phoneNumber);
    }

    @PostMapping("/jsonPostTest")
    public void jsonPostTest(@RequestBody @Valid TestReqDTO reqDTO) {
        log.info("TestController#jsonPostTest, reqDTO: {}", reqDTO);
    }

    @PostMapping("/inListTest")
    public void inListTest(@RequestBody @Valid TestInListReqDTO reqDTO) {
        log.info("TestController#inListTest, reqDTO: {}", reqDTO);
    }

    @PostMapping("/paramNotBlank")
    public void paramNotBlank(@RequestParam(name = "userCode") @Valid @NotBlank(message = "用户代码不能为空") String userCode,
                              @RequestParam(name = "userId") Long userId) {
        log.info("TestController#paramNotBlank, userCode: {}, userId: {}", userCode, userId);
    }

}
